<template>
  <div class="caseComp">
    <div class="caseCompTitle">编辑被投诉单位</div>
    <div class="caseCompList">
      <span class="caseCompListTitle">是否重复诉求</span>
      <el-radio-group v-model="info.isRepeat">
        <el-radio label="1" fill="#009588">是</el-radio>
        <el-radio label="0" fill="#009588">否</el-radio>
      </el-radio-group>
    </div>
    <div class="caseCompList">
      同诉求事件首条欠薪诉求
      <el-input
        v-model="info.fristNumId"
        :disabled="info.isRepeat == '0'"
        placeholder="请输入同诉求事件首条欠薪诉求编号"
        class="input"
      ></el-input>
    </div>
    <div class="caseCompBtn">
      <el-button
        type="primary"
        v-sdc
        :loading="isLoading"
        class="commonBut saveBtn"
        @click="save"
        >保存</el-button
      >
      <el-button type="default" v-sdc class="commonBut" @click="finish"
        >取消</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: 'caseType',
  props: {
    childData: {
      type: Object,
      required: true,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      isLoading: false,
      info: {
        id: '',
        isRepeat: 1,
        fristNumId: '',
      },
    }
  },
  watch: {
    newIsRepeat(val) {
      if (val === '0') {
        this.info.fristNumId = ''
      }
    },
  },
  computed: {
    newIsRepeat() {
      return this.info.isRepeat
    },
  },
  mounted() {
    const { id, isRepeat, fristNumId } = this.childData
    this.info = { id, isRepeat: isRepeat + '', fristNumId }
  },

  methods: {
    save() {
      const { id, isRepeat, fristNumId } = this.info
      let params = { id, isRepeat, repeatNum: fristNumId }
      if (isRepeat == 1 && !fristNumId) {
        this.$message({
          type: 'warning',
          message: '同诉求事件首条欠薪诉求编号为空',
        })
        return false
      }
      this.axios
        .post('api-r/rbp/modifyRightsAppealType', params)
        .then((res) => {
          if (!res.data.hasError) {
            this.$message({
              type: 'success',
              message: res.data.msg,
            })
            this.isLoading = false
            this.finish(1)
          } else {
            this.$message({
              type: 'warning',
              message: res.data.errorMsg,
            })
            this.isLoading = false
          }
        })
    },
    finish(index) {
      this.$emit('callback', { success: index == 1 ? true : false })
    },
  },
}
</script>
<style lang="less" scoped>
.caseComp {
  border: 1px solid #dcdfe6;
  background-color: #f8f9fb;
  padding: 15px;
  &Title {
    color: #009588;
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 12px;
  }
  &List {
    line-height: 36px;
    height: 36px;
    font-size: 14px;
    color: #444;
    margin-bottom: 12px;
    &Title {
      width: 85px;
    }
    .input {
      width: calc(100% - 170px);
    }
  }
  &Btn {
    text-align: center;
    margin: 24px 0 10px;
    .el-button {
      width: 120px;
    }
  }
  /deep/ .el-radio__input.is-checked + .el-radio__label {
    color: #009588 !important;
  }
  /deep/.el-radio__input.is-checked .el-radio__inner {
    background: #009588 !important;
    border-color: #009588 !important;
  }
}
</style>
